package torres.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.HashMap;

import javax.swing.JPanel;

import torres.entity.Entity;
import torres.entity.NPC;
import torres.map.World;

@SuppressWarnings("serial")
public class SkillMenuView extends JPanel {
	
	int screenWidth, x, width;
	int screenHeight, y, height;
	NPC entity;
	Entity player;
	HashMap<Integer, Dimension> skillMenuTable;
	
	public SkillMenuView() {
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		screenWidth = screenSize.width;
		screenHeight = screenSize.height;
		
		setIgnoreRepaint(true);
		setPreferredSize(new Dimension(width,2*height));
		setLocation(x, y);
		setLayout(null);
		setVisible(true);
		setFocusable(true);
		setOpaque(true);
		
		skillMenuTable = new HashMap<Integer, Dimension>();
		
		player = World.getInstance().getPlayer();
	}
	
	public void paintComponent(Graphics g) {
		
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		
		g.setColor(Color.black);
		drawWindow(g);
		
		//int yOffset = 30;
		//int xOffset = 20;
		
		Font body = new Font("Helvetica",Font.BOLD, 22);
		
		g.setFont(body);
		g.setColor(Color.black);
		drawActions(g2);
	}
	
	public void drawWindow(Graphics g) {
		ImageLoader loader = new ImageLoader("actionMenuTexture.jpg");
		BufferedImage img = loader.getImage();
//		Direction dir = player.getDirection();
		if(x!=0&&y!=0) g.drawImage(img,x,y,width,2*height,null);
	}
	
	public void drawActions(Graphics2D g2) {
		//System.out.println("Drawing at "+x+" "+y);
		g2.draw3DRect(x, y, width, height, true);
		g2.draw3DRect(x, y, width, 2*height, true);
		g2.drawString("Pickpocket", x,y+screenHeight/22);
		g2.drawString("Backstab", x,y+screenHeight/11);
		skillMenuTable.put(1, new Dimension(x, y));
		skillMenuTable.put(2, new Dimension(x, y+height));
	}
	
	public void update(Graphics g) {
		update(g, x, y, width, height);
	}
	
	public void update(Graphics g, double x, double y, int width, int height) {
		this.x = (int)x;
		this.y = (int)y;
		this.width = width;
		this.height = height;
		paintComponent(g);
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}

	public HashMap<Integer, Dimension> getSkillMenuTable() {
		return skillMenuTable;
	}
}
